#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int kind, maxWeight;
    cin >> kind >> maxWeight;

    vector<int> weight(kind + 1), value(kind + 1);
    vector<int> dp(maxWeight + 1);
    for (int i = 1; i <= kind; ++i) {
        cin >> weight[i] >> value[i];
    }

    for (int i = 1; i <= kind; ++i) {
        for (int j = maxWeight; j >= 1; --j) {
            for (int k = 0; k <= j / weight[i]; ++k) {
                dp[j] = max(dp[j], dp[j - k * weight[i]] + k * value[i]);
            }
        }
    }

    cout << dp[maxWeight] << endl;
    return 0;
}
